﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="FL.Web.BackEnd.DataGrid" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="/SFramework/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
    <script src="/SFramework/boot.js"></script>
    <script src="/SFramework/ztree/js/jquery.ztree.all-3.3.js"></script>
</head>

<body style="margin: 0px; padding: 0px">
    <form id="form1" runat="server">
        <div style="width: 100%; height: 100%">
            <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
                <table style="width: 100%;">
                    <tr>
                        <td style="width: 100%;">
                                <a class="mini-button" iconcls="icon-ok" plain="true" onclick="onOk()">确定</a>
                               <a class="mini-button" iconcls="icon-cancel" plain="true" onclick="onCancel()">取消</a>
                        </td>
                        
                    </tr>
                </table>
            </div>
        </div>
        <div><ul id="tree" class="ztree" url="/extendpage/data/jsondata.aspx?entity=<% =EntityName %>&type=1&order=path&desc=No"></ul></div>
    </form>
</body>

<script type="text/javascript">
    /* 树 */
    var setting = { 
        edit: {
            drag: {
            },
            enable: true,
            showRemoveBtn: false,
            showRenameBtn: false,
            editNameSelectAll: false
        },
        data: {
            key: {
                title: "t"
            },
            simpleData: {
                enable: true,
                idKey:"id",
                pIdKey:"parent_id"
            }
        },
        callback: {
            //onClick: onClick
        }
    };
    var url = "/extendpage/data/jsondata.aspx?entity=<% =EntityName %>&type=1&order=path&desc=Yes";
    $.get(url,//$("#tree1").attr("url")
     function (d, t) {
         var data = eval("(" + d + ")");
         $.fn.zTree.init($("#tree"), setting, data);
     });


    function fnSeTreeData(node) {
        fnRunProc2("usp_sys_set_tree_data_path", node.id + "," + node.parent_id + "," + node.path + "," + node.sort+",<%=EntityName%>", function () { });
    }

    function onCreateTreeCode(node) {
        if (!node||node == null) {
            var zTree = $.fn.zTree.getZTreeObj("tree");
            var root = zTree.getNodes()[0];
            onCreateTreeCode(root);
        } else {
            if (typeof (node.children) == "undefined") {
                return;
            }
            //for (var i = 0; i < node.children.length; i++) {
            //    node.children[i].path = node.path + "-" + pad(i + 1, 3);
            //    node.children[i].parent_id = node.id;
            //    node.children[i].sort = i + 1;
            //    fnSeTreeData(node.children[i]);
            //    onCreateTreeCode(node.children[i]);
            //}
            for (var i = node.children.length-1; i >=0; i--) {
                node.children[i].path = node.path + "-" + pad(i + 1, 3);
                node.children[i].parent_id = node.id;
                node.children[i].sort = i + 1;
                fnSeTreeData(node.children[i]);
                onCreateTreeCode(node.children[i]);
            }

        }
    }


    //自动补0
    function pad(num, n) {
        return (new Array(n > ('' + num).length ? (n - ('' + num).length + 1) : 0).join('0') + num);
    }

    function onOk() {
        onCreateTreeCode();
        //CloseWindow("ok");
    }
    function onCancel() {
        CloseWindow("cancel");
    }
</script>
<script type="text/javascript">
</script>
<script src="/Scripts/common/jquery.action.js"></script>
<script src="/Scripts/common/jquery.data.js"></script>
</html>
